package com.yinkgh.demo;

import java.nio.charset.Charset;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;


//代码说明：
//1、@SpringBootApplication：Spring Boot项目的核心注解，主要目的是开启自动配置。；
//2、@Configuration：这是一个配置Spring的配置类；
//3、@Controller：标明这是一个SpringMVC的Controller控制器；
//4、main方法：在main方法中启动一个应用，即：这个应用的入口；
@Controller
@SpringBootApplication
@Configuration
public class HelloApplication {

	@RequestMapping(value="/")
    @ResponseBody
    public String hello(){
		
        return "这是一个hello world <a color='blue' href='nituwang.jpg'>[点我看图片]</a>";
    }
	
	/**
	 * 访问WEB-INF下jsp页面
	 * @return
	 */
//	@RequestMapping("/main.action")
	@RequestMapping("/main")
	@ResponseBody
    public ModelAndView showIndex(){
		ModelAndView modelAndView = new ModelAndView("MainIndex");
        return modelAndView;
    }
    
	//消息转换器 测试 改为ISO-8859-1中文会不正常 
	@Bean
	public StringHttpMessageConverter stringHttpMessageConverter() {
		StringHttpMessageConverter converter = new StringHttpMessageConverter(Charset.forName("ISO-8859-1"));
//			StringHttpMessageConverter converter = new StringHttpMessageConverter(Charset.forName("UTF-8"));
		return converter;
	}
	
    public static void main(String[] args) {
        SpringApplication.run(HelloApplication.class, args);
    }
}
